import 'package:backend.core/core/domain/entities/api/web/api_web_one_time_purchased_item.dart';
import 'package:backend.core/core/domain/entities/api/web/api_web_purchased_item.dart';
import 'package:backend.core/core/domain/entities/api/web/api_web_purchased_subscription.dart';
import 'package:backend.purchases/infrastructure/dtos/api/web/api_web_one_time_purchased_item_dto.dart';
import 'package:backend.purchases/infrastructure/dtos/api/web/api_web_purchased_item_dto.dart';
import 'package:backend.purchases/infrastructure/dtos/api/web/api_web_purchased_subscription_dto.dart';

class ApiWebPurchasedItemDtoFactory {
  const ApiWebPurchasedItemDtoFactory._internal();

  static const _instance = ApiWebPurchasedItemDtoFactory._internal();

  factory ApiWebPurchasedItemDtoFactory() {
    return _instance;
  }

  ApiWebPurchasedItemDto fromEntity(ApiWebPurchasedItem purchasedItem) {
    if (purchasedItem is ApiWebOneTimePurchasedItem) {
      return ApiWebOneTimePurchasedItemDto.fromEntity(purchasedItem);
    }

    if (purchasedItem is ApiWebPurchasedSubscription) {
      return ApiWebPurchasedSubscriptionDto.fromEntity(purchasedItem);
    }

    throw UnimplementedError();
  }
}
